/**
 * 测试
 */
public class Demo2 {

    private static int f(final char[] s) {
        char[] t = "azzz".toCharArray();
        int count = 0;
        boolean b;
        while (!match(s, t)) {
            b = true;
            for (int i = 1; i < 4; i++) {
                if (t[i] == 'z') {
                    b = false;
                    t[i] = 'a';
                    break;
                }
            }
            if (b) {
                for (int j = 3; j >= 0; j--) {
                    if (t[j] != 'y') {
                        t[j] = (char) (t[j] + 1);
                        for (int k = j + 1; k < 4; k++)
                            t[k] = 'z';
                        break;
                    }
                }
            }
            count++;
        }
        return count;
    }

    private static boolean match(final char[] s, final  char[] t) {
        int i;
        for (i = 0; i < s.length; i++) {
            if (s[i] != t[i])
                return false;
        }
        if (i < 4 && t[i] != 'z')
            return false;
        return true;
    }

    public static void main(String[] args) {
        char[] s = "yyyy".toCharArray();
        Long start = System.currentTimeMillis();
        int index = f(s);
        Long end = System.currentTimeMillis();
        System.out.println(index + " : " + (end - start) + " ms");
    }
}
